$(function(){

	var register = {
		sendData: function() {
			$('[data-role="register"]').on('click', function() {
				var name = $('[data-role="name"]').val();
				var password = $('[data-role="password"]').val();
				var repassword = $('[data-role="repassword"]').val();
				if(name == '') {
					iosOverlay({
						text: "账号不能为空!",
						duration: 1500
					});
					return;
				}
				if(password == '') {
					iosOverlay({
						text: "密码不能为空!",
						duration: 1500
					});
					return;
				}
				if(repassword == '') {
					iosOverlay({
						text: "确认密码不能为空!",
						duration: 1500
					});
					return;
				}
				if(password != repassword) {
					iosOverlay({
						text: "密码与确认密码不相符，请重新填写!",
						duration: 1500
					});
					return;
				}
				if(!$('#license').prop('checked')) {
					iosOverlay({
						text:"请先同意注册协议!",
						duration: 1500
					});
					return;
				}
				$.ajax({
					url: wsCommon.host + '/api/member/register',
					dataType: wsCommon.jsonType,
					data: {
						loginAccount: name,
						loginPassword: password,
						license: 'on'
					},
					success: function(res) {
						if(res.result) {
							iosOverlay({
								text: "注册成功，正在跳转页面!",
								duration: 1500,
								onbeforehide: function() {
									wsCommon.setCookie('uid', res.data.user.memberId);
									window.location.href = './passport-signup-result.html';
								}
							});
						} else {
							iosOverlay({
								text: res.reason,
								duration: 1500
							});
						}
					},
					error: function() {
						// console.log('注册显示接口返回失败');
					}
				})

			})
		},
		passwordJy: function() {
			//密码强度
			$('#dom_el_64073e1').keyup(function () {
				var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
				var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
				var enoughRegex = new RegExp("(?=.{6,}).*", "g");

				if (false == enoughRegex.test($(this).val())) {
					$(".password-check").attr("class","password-check");
					 //密码小于六位的时候，密码强度图片都为灰色
				}
				else if (strongRegex.test($(this).val())) {
					$(".password-check").attr("class","password-check password-strong");
					 //密码为八位及以上并且字母数字特殊字符三项都包括,强度最强
				}
				else if (mediumRegex.test($(this).val())) {
					$(".password-check").attr("class","password-check password-good");
					 //密码为七位及以上并且字母、数字、特殊字符三项中有两项，强度是中等
				}
				else {
					$(".password-check").attr("class","password-check password-weak");
					 //如果密码为6为及以下，就算字母、数字、特殊字符三项都包括，强度也是弱的
				}
				return true;
			});
		},
		init: function() {
			this.sendData();
			this.passwordJy();
		}
	}

	register.init();
})
